import React, {useState, useEffect} from 'react';

import {NavBar, Icon, Badge, Tabs, List, Toast, Button, Result, Card, ListView} from 'antd-mobile';

import {GetListRefund, GetProducingApplies, FailOrder} from "@/api/tutor/orderList.js"

import {createForm} from 'rc-form'
import _ from 'lodash';

import {R, ORDER_STATUSES} from "@/assets/js/dict"


import './orderList.scss';
import nodata from "@/assets/svg/nodata.svg"
import PreOrderDetails from "./tutorOrderDetails/PreOrderDetails";
/*
* 家教待定订单壳子
* */
function PreOrderOfTutor(props) {
    console.log("PreOrderOfTutor---> ", props);
    let [userInfo] = useState(() => {
        let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
        return userInfo
    });
    let [flush, setFlush] = useState("");

    function doFlush() {
        setFlush(new Date().getTime());
    }

    let [pending, setPending] = useState({});  // 待定

    // 待定订单，只有一个，直接展示详情页
    function getPendingOrder(pageNum, pageSize) {
        GetProducingApplies({tutor_id: userInfo.id, pageNum: pageNum, pageSize: pageSize}).then(res => {
            if (res.code === '000000') {
                let data = R.getData(res);
                if (!!data) {
                    setPending(data);
                }
            }
        }).catch(err => {
            console.log(err)
        })
    }


    useEffect(() => {
        getPendingOrder(1, 10)
    }, [flush]);

    function back() {
        props.history.push({
            pathname: '/mainTutor'
        });
    }

    const myImg = src => <img src={src} className="spe am-icon am-icon-md" alt=""/>;

    return (
        <div className="orderDetails">
            <div className="page-title  home-tit">
                <NavBar
                    mode="light"
                    icon={<Icon type="left"/>}
                    onLeftClick={back}
                >
                    待定订单
                </NavBar>
            </div>

            <div className="page-content  home-content">
                {pending !== null && !!pending.id ?
                    <PreOrderDetails doFlush={doFlush} orderDetailsObject={pending}/> :
                    <Result
                        buttonText={"返回主页"}
                        img={myImg(nodata, "none")}
                        title=""
                        message="暂无数据"
                        buttonType="primary"
                        onButtonClick={() => props.history.push("/mainTutor")}
                    />}
            </div>
        </div>);
}

PreOrderOfTutor = createForm()(PreOrderOfTutor);

export default PreOrderOfTutor;